package myjava.algorithm.leetcode;

//https://oj.leetcode.com/problems/excel-sheet-column-title/

public class ExcelSheetColumnTitle {
	public static String convertToTitle(int n) {
		StringBuilder sb = new StringBuilder();

		for(;;)
		{
			if(n<=0) break;
			
			int temp = n%26;
			
			if(temp > 0)
			{
				sb.insert(0,(char)('A' + (temp - 1)));
				
				n= (n - temp)/26;
			}
			else if(temp == 0)
			{
				sb.insert(0, 'Z');
				n = (n-temp)/26 - 1;
			}
		}
		
		
        return sb.length() == 0 ?"" : sb.toString();
    }
	public static void main(String[] args)
	{
		System.out.println(String.valueOf('A'));
		System.out.println(convertToTitle(79));
	}
}
